<?php
/**
 * Created by PhpStorm.
 * Author: sitewang@aliyun.com
 * CreateTime: 2023/11/6 22:39
 * Blog：www.myblogs.xyz
 */

namespace app\infrastructure\model;

trait BaseTrait
{
	// 指定AND查询条件
	private static $wheres = '';
	// 指定RAW查询条件
	private static $whereRaws = '';
	// 字段截取
	private static $fields = '';
	// 排序
	private static $orders = '';
	// 指定OR查询条件
	private static $whereOr = '';
	// 指定withs查询
	private static $withs = [];
	// 是否查询加锁
	private static $locks = false;

	public static function locks($locks = false)
	{
		if (!empty($locks)){
			self::$locks = $locks;
		}
		return self::$locks;
	}

	public static function wheres($wheres = '')
	{
		if (!empty($wheres)){
			self::$wheres = $wheres;
		}
		return self::$wheres;
	}

	public static function whereRaws($whereRaws = '')
	{
		if (!empty($whereRaws)){
			self::$whereRaws = $whereRaws;
		}
		return self::$whereRaws;
	}

	public static function fields($fields = '')
	{
		if (!empty($fields)){
			self::$fields = $fields;
		}
		return self::$fields;
	}
	public static function orders($orders = '')
	{
		if (!empty($orders)){
			self::$orders = $orders;
		}
		return self::$orders;
	}

	public static function whereOrs($whereOrs = '')
	{
		if (!empty($whereOrs)){
			self::$whereOr = $whereOrs;
		}
		return self::$whereOr;
	}

	public static function withs($withs = [])
	{
		if (!empty($withs)){
			self::$withs = $withs;
		}
		return self::$withs;
	}

	// 重置查询参数
	protected static function resetQuery(): void
	{
		self::$wheres = '';
		self::$whereRaws = '';
		self::$fields = '';
		self::$orders = '';
		self::$whereOr = '';
		self::$withs = [];
		self::$locks = false;
	}
}